package com.warm.json.config;

import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.noear.solon.serialization.jackson.JacksonActionExecutor;
import org.noear.solon.serialization.jackson.JacksonRenderFactory;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@Configuration
public class JsonConfig {
    @Bean
    public void jsonInit(JacksonRenderFactory factory, JacksonActionExecutor executor) {
        // 方式1：通过转换器，做简单类型的定制
        factory.addConvertor(Date.class, Date::getTime);
        factory.addConvertor(LocalDate.class, s -> s.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        factory.addConvertor(LocalDateTime.class, s -> s.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
        factory.addConvertor(Long.class, String::valueOf);

    }
}